<!DOCTYPE html>
<html>
<!--
Copyright 2008 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<!--
Author: attila@google.com (Attila Bodis)
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Closure Unit Tests - goog.ui.TabRenderer</title>
  <script src="../base.js"></script>
  <script>
    goog.require('goog.dom');
    goog.require('goog.a11y.aria.Role');
    goog.require('goog.dom.classlist');
    goog.require('goog.testing.jsunit');
    goog.require('goog.ui.Tab');
    goog.require('goog.ui.TabRenderer');
    goog.require('goog.testing.dom');
    goog.require('goog.testing.ui.rendererasserts');
  </script>
</head>
<body>
  <div id="sandbox"></div>
  <script>
    var sandbox = goog.dom.getElement('sandbox');
    var renderer = goog.ui.TabRenderer.getInstance();
    var tab;
  
    function setUp() {
      tab = new goog.ui.Tab('Hello');
    }
    
    function tearDown() {
      tab.dispose();
      goog.dom.removeChildren(sandbox);
    }

    function testConstructor() {
      assertNotNull('Renderer must not be null', renderer);
    }

    function testGetCssClass() {
      assertEquals('CSS class must have expected value',
          goog.ui.TabRenderer.CSS_CLASS, renderer.getCssClass());
    }

    function testGetAriaRole() {
      assertEquals('ARIA role must have expected value',
          goog.a11y.aria.Role.TAB, renderer.getAriaRole());
    }

    function testCreateDom() {
      var element = renderer.createDom(tab);
      assertNotNull('Element must not be null', element);
      goog.testing.dom.assertHtmlMatches(
          '<div class="goog-tab" aria-selected="false">Hello</div>',
          goog.dom.getOuterHtml(element));
    }

    function testCreateDomWithTooltip() {
      tab.setTooltip('Hello, world!');
      var element = renderer.createDom(tab);
      assertNotNull('Element must not be null', element);
      assertEquals('Element must have expected tooltip', 'Hello, world!',
          renderer.getTooltip(element));
    }

    function testDecorate() {
      sandbox.innerHTML =
          '<div id="foo">Foo</div>\n' +
          '<div id="bar" title="Yes">Bar</div>';

      var foo = renderer.decorate(tab, goog.dom.getElement('foo'));
      assertNotNull('Decorated element must not be null', foo);
      assertSameElements('Decorated element must have expected class',
          ['goog-tab'], goog.dom.classlist.get(foo));
      assertEquals('Decorated tab must have expected content', 'Foo',
          tab.getContent().nodeValue);
      assertUndefined('Decorated tab must not have tooltip', tab.getTooltip());
      assertEquals('Decorated element must not have title', '',
          renderer.getTooltip(foo));

      var bar = renderer.decorate(tab, goog.dom.getElement('bar'));
      assertNotNull('Decorated element must not be null', bar);
      assertSameElements('Decorated element must have expected class',
          ['goog-tab'], goog.dom.classlist.get(bar));
      assertEquals('Decorated tab must have expected content', 'Bar',
          tab.getContent().nodeValue);
      assertEquals('Decorated tab must have expected tooltip', 'Yes',
          tab.getTooltip());
      assertEquals('Decorated element must have expected title', 'Yes',
          renderer.getTooltip(bar));
    }

    function testGetTooltip() {
      sandbox.innerHTML =
          '<div id="foo">Foo</div>\n' +
          '<div id="bar" title="">Bar</div>\n' +
          '<div id="baz" title="BazTitle">Baz</div>';
      assertEquals('getTooltip() must return empty string for no title', '',
          renderer.getTooltip(goog.dom.getElement('foo')));
      assertEquals('getTooltip() must return empty string for empty title', '',
          renderer.getTooltip(goog.dom.getElement('bar')));
      assertEquals('Tooltip must have expected value', 'BazTitle',
          renderer.getTooltip(goog.dom.getElement('baz')));
    }

    function testSetTooltip() {
      sandbox.innerHTML = '<div id="foo">Foo</div>';
      var element = goog.dom.getElement('foo');

      renderer.setTooltip(null, null); // Must not error.

      renderer.setTooltip(element, null);
      assertEquals('Tooltip must be the empty string', '', element.title);

      renderer.setTooltip(element, '');
      assertEquals('Tooltip must be the empty string', '', element.title);

      renderer.setTooltip(element, 'Foo');
      assertEquals('Tooltip must have expected value', 'Foo', element.title);
    }

    function testDoesntCallGetCssClassInConstructor() {
      goog.testing.ui.rendererasserts.
          assertNoGetCssClassCallsInConstructor(goog.ui.TabRenderer);
    }
  </script>
</body>
</html>
